import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.sql.Date;


public class WriteObject {
	
	public static void main(String[] args) {
		
		
		
		Employee employee=new Employee();
		employee.setId(101);
		employee.setName("Demo user");
		employee.setSalary(450000);
		employee.setAge(24);
		employee.setDatofBirth(new Date(System.currentTimeMillis()));
		employee.setNickName("mep1");
		
		 try {
			 File  file=new File("c:\\javaprg\\emp.db");
			 
			 if(file.exists()){
				 file.delete();
			 }
			 file.createNewFile();
			 
			 FileOutputStream fileOutputStream=new FileOutputStream(file,true);
			 
			 ObjectOutputStream objectOutputStream=new ObjectOutputStream(fileOutputStream);
			 objectOutputStream.writeObject(employee);
			  
			 objectOutputStream.flush();
			 objectOutputStream.close();
			 fileOutputStream.close();
			  System.out.println("object written successfully");
			  
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
